package org.openwebtop.sunshine.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.openwebtop.sunshine.domain.CodeRepository;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class CodeRepositoryDAO extends HibernateDaoSupport {

	public CodeRepository getCodeRepository(String name) {
		return (CodeRepository)getHibernateTemplate().get(CodeRepository.class, name);
	}

	@SuppressWarnings("unchecked")
	public List<CodeRepository> getCodeRepositories() {
		final DetachedCriteria criteria = DetachedCriteria.forClass(CodeRepository.class);
		criteria.addOrder(Order.asc("name"));

		return getHibernateTemplate().findByCriteria(criteria);
	}

}
